<?php

	// TITLE: Driver_license AUTO MODEL
	// FILE: scaffolding/model/driver_license.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createDriverLicense = function($con, $driverLicense) {
		$sql = 'INSERT INTO driver_license (person_id, number, state_id, file_path) VALUES (';
		$sql .= $driver_license->getPersonId() . ', ';
		$sql .= $driver_license->getNumber() . ', ';
		$sql .= $driver_license->getStateId() . ', ';
		$sql .= $driver_license->getFilePath() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readDriverLicense = function($con, $id) {
		$sql = 'SELECT * FROM driver_license WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$driverLicense = new DriverLicense();
			$driverLicense->setPersonId($dbio->select($readPerson(result[0])));
			$driverLicense->setNumber(result[1]);
			$driverLicense->setStateId($dbio->select($readState(result[2])));
			$driverLicense->setFilePath(result[3]);
		} else {
			$driverLicense = false;
		}
		return $driverLicense;
	};

	$updateDriverLicense = function($con, $driverLicense) {
		$sql = 'UPDATE driver_license SET ';
		$sql .= 'person_id = ' . $driver_license->getPersonId() . ', ';
		$sql .= 'number = ' . $driver_license->getNumber() . ', ';
		$sql .= 'state_id = ' . $driver_license->getStateId() . ', ';
		$sql .= 'file_path = ' . $driver_license->getFilePath() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteDriverLicense = function($con, $id) {
		$sql = 'DELETE FROM driver_license WHERE person_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listDriverLicense = function($con) {
		$sql = 'SELECT * FROM driver_license';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$driverLicenses = array();
			while ($result = mysqli_fetch_array($results)) {
				$driverLicense = new DriverLicense();
				$driverLicense->setPersonId($dbio->select($readPerson(result[0])));
				$driverLicense->setNumber(result[1]);
				$driverLicense->setStateId($dbio->select($readState(result[2])));
				$driverLicense->setFilePath(result[3]);
				$driverLicenses[] = driverLicense;
			}// end while
		} else {
			$driverLicenses = false;
		}
		return $driverLicenses;
	};

